<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/4
 * Time: 14:09
 */
include("check.php");
include("check2.php");
include_once("../function.php");

header("Content-Type: text/html;charset=utf-8");
session_start();

#搜索商品
if ($_POST['Search']){
    $SearchContent=$_POST['SearchContent'];
    $TimeStart=$_POST['TimeStart'];
    $TimeEnd=$_POST['TimeEnd'];
    if ($TimeStart!=NULL){
        if ($TimeEnd==NULL){
            $TimeEnd=now();
        }
        $_SESSION['SearchTime']="and (tdate>='".$TimeStart."' and tdate<='".$TimeEnd."') or (fdate>='".$TimeStart."' and fdate<='".$TimeEnd."')";
    }else{
        $_SESSION['SearchTime']=NULL;
    }
//    if ($SearchContent!=NULL){
        $SearchType=$_POST['SearchType'];
        if ($SearchType==1){
            #搜索订单编号
             $_SESSION['Search']="and isgrant =1";
        }else if($SearchType==2){
            $_SESSION['Search']="and isgrant =0";
        }else if($SearchType==2){
            $_SESSION['Search']="and username like '%".$SearchContent."%'";
        }
/*    }else{
        $_SESSION['Search']=NULL;
    }*/
}else{
    if ($_GET['page']==NULL){
        $_SESSION['Search']=NULL;
        $_SESSION['SearchTime']=NULL;
    }
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <script src="../js/calendar.js"></script>
    <title>订单列表</title>
</head>
<body>
<form name="form1" method="post" action="?">
    <div class="ziti">
        <select name="SearchType" id="SearchType">
            <option value="1">交易成功</option>
            <option value="2">挂卖中</option>
        </select>
        <input type="text" name="SearchContent" id="SearchContent" style="display: none">
        搜索时间范围：
        <input type="text" name="TimeStart" id="TimeStart" style="width:100px" onFocus="HS_setDate(this)" >
        至
        <input type="text" name="TimeEnd" id="TimeEnd" style="width:100px" onFocus="HS_setDate(this)">
        <input type="submit" name="Search" id="Search" class="button_blue" value="搜  索">
    </div>
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
            <td height="10" colspan="12" align="center">交易记录</td>
        </tr>
        <tr>
            <td align="center">编号</td>
            <td align="center">会员编号</td>
            <td align="center">会员姓名</td>
            <td align="center">购买人</td>
            <td align="center">会员姓名</td>
            <td align="center">购买单价</td>
            <td align="center">购买数量</td>
            <td align="center">手续费</td>
            <td align="center">总金额</td>
            <td align="center">挂卖时间</td>
            <td align="center">交易时间</td>
            <td align="center">状态</td>
<!--            <td align="center">操作</td>-->
        </tr>
        <?php
        $pagesize = 20; //设置每页记录数
        $sql = "SELECT * FROM `guamai` WHERE 1=1 and uid=".$_SESSION['ID']." or bdid=".$_SESSION['ID']." ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
        if($query = mysql_query($sql)){
            $sum = mysql_num_rows($query); //计算总记录数
        }else{
            $sum=0;
        }
        if($sum % $pagesize == 0) //计算总页数
            $total = (int)($sum/$pagesize);
        else
            $total = (int)($sum/$pagesize) + 1;
        if (isset($_GET['page'])) //获得页码
        {
            $p = (int)$_GET['page'];
        }
        else
        {
            $p = 1;
        }
        if ($p>$total){
            $p=$total;
        }
        $start = $pagesize * ($p - 1); //计算起始记录
        $sql = "SELECT * FROM `guamai` WHERE 1=1 and uid=".$_SESSION['ID']."  or bdid=".$_SESSION['ID']."  ".$_SESSION['Search']." ".$_SESSION['SearchTime']." order by id desc limit ".$start.",".$pagesize;
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                if($row['bdid']){
                    $us=getMemberbyID($row['bdid']);
                }

                ?>
                <tr>
                    <td align="center"><?=$row['id']?></td>
                    <td align="center"><?=$row['nickname']?></td>
                    <td align="center"><?=$row['username']?></td>
                    <td align="center"><?=$us['nickname']?></td>
                    <td align="center"><?=$us['username']?></td>
                    <td align="center"><?=$row['shouxu']?></td>
                    <td align="center"><?=$row['jine']*0.75?></td>
                    <td align="center"><?=$row['yingshi']?></td>
                    <td align="center"><?=$row['aixinjijin']?></td>
<!--                    <td align="center"><?/*=$row['usertel']*/?></td>
                    <td align="center"><?/*=$row['useraddress']*/?></td>-->
                    <td align="center"><?=$row['tdate']?></td>
                    <td align="center"><?=$row['fdate']?></td>
                    <td align="center"><?php if($row['isgrant']==0){?>挂卖中<?php }else if($row['isgrant']==1){ ?>交易成功<?php }else if($row['issend']==2){?>已退款<?php }?></td>
                    <!--<td align="center"><a href="ordercontent.php?oid=<?/*=$row['id']*/?>&page=<?/*=$p*/?>" style="text-decoration:none">查看</a></td>-->
                </tr>
                <?php
            }
        }
        ?>
    </table>
    <table width="100%" border="0" class="ziti">
        <tr>
            <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
        </tr>
    </table>
</form>
</body>
</html>